#include "DIALOG.h"
#include "MC_include.h"
#include "Maintask.h"

#define ID_FRAMEWIN_2     (GUI_ID_USER + 0x60)
#define ID_HBUTTON_0     (GUI_ID_USER + 0x61)
#define ID_HBUTTON_1     (GUI_ID_USER + 0x62)
#define ID_HBUTTON_2     (GUI_ID_USER + 0x63)
#define ID_HBUTTON_3     (GUI_ID_USER + 0x64)
#define ID_HBUTTON_4     (GUI_ID_USER + 0x65)
#define ID_HBUTTON_5     (GUI_ID_USER + 0x66)
#define ID_HBUTTON_6     (GUI_ID_USER + 0x67)
#define ID_HBUTTON_7     (GUI_ID_USER + 0x68)
#define ID_HBUTTON_8     (GUI_ID_USER + 0x69)
#define ID_HBUTTON_9     (GUI_ID_USER + 0x6A)
#define ID_HBUTTON_10     (GUI_ID_USER + 0x6B)
#define ID_HBUTTON_11     (GUI_ID_USER + 0x6C)
#define ID_HBUTTON_12     (GUI_ID_USER + 0x6D)
#define ID_HBUTTON_13     (GUI_ID_USER + 0x6E)
#define ID_HTEXT_0     (GUI_ID_USER + 0x70)
#define ID_HEDIT_0     (GUI_ID_USER + 0x71)
#define ID_HBUTTON_14     (GUI_ID_USER + 0x72)
#define ID_HBUTTON_15     (GUI_ID_USER + 0x73)
#define ID_HBUTTON_16     (GUI_ID_USER + 0x74)
#define ID_HBUTTON_17     (GUI_ID_USER + 0x75)
#define ID_HTEXT_1     (GUI_ID_USER + 0x76)
#define ID_HTEXT_2     (GUI_ID_USER + 0x77)
#define ID_HTEXT_3     (GUI_ID_USER + 0x78)
#define ID_HTEXT_4     (GUI_ID_USER + 0x79)
#define ID_HTEXT_5     (GUI_ID_USER + 0x7A)
#define ID_HTEXT_6     (GUI_ID_USER + 0x7B)
#define ID_HTEXT_7     (GUI_ID_USER + 0x7C)
#define ID_HTEXT_8     (GUI_ID_USER + 0x7D)
#define ID_HEDIT_1     (GUI_ID_USER + 0x7E)
#define ID_HEDIT_2     (GUI_ID_USER + 0x7F)
#define ID_HTEXT_9     (GUI_ID_USER + 0x80)
#define ID_HBUTTON_18     (GUI_ID_USER + 0x81)
#define ID_HBUTTON_19     (GUI_ID_USER + 0x82)
#define ID_HTEXT_10     (GUI_ID_USER + 0x83)
#define ID_HTEXT_11     (GUI_ID_USER + 0x85)
#define ID_HTEXT_12     (GUI_ID_USER + 0x86)
#define ID_HTEXT_13     (GUI_ID_USER + 0x87)
#define ID_HTEXT_14     (GUI_ID_USER + 0x88)
#define ID_HTEXT_15     (GUI_ID_USER + 0x89)
#define ID_HTEXT_16		(GUI_ID_USER + 0x8a)
#define ID_HTEXT_17		(GUI_ID_USER + 0x8b)
#define ID_HBUTTON_20     (GUI_ID_USER + 0x8C)
#define ID_HBUTTON_21     (GUI_ID_USER + 0x8D)
#define ID_HBUTTON_22  (GUI_ID_USER + 0x8F)

static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] =
{
    { FRAMEWIN_CreateIndirect, "Framewin", ID_FRAMEWIN_2, 0, 0, 800, 480, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "1", ID_HBUTTON_0, 515, 225, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "2", ID_HBUTTON_1, 570, 225, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "3", ID_HBUTTON_2, 625, 225, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "4", ID_HBUTTON_3, 515, 280, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "5", ID_HBUTTON_4, 570, 280, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "6", ID_HBUTTON_5, 625, 280, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "7", ID_HBUTTON_6, 515, 337, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "8", ID_HBUTTON_7, 570, 337, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "9", ID_HBUTTON_8, 625, 337, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "0", ID_HBUTTON_9, 570, 390, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, ".", ID_HBUTTON_10, 625, 390, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "-", ID_HBUTTON_11, 515, 390, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Del", ID_HBUTTON_12, 690, 275, 45, 50, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "Enter", ID_HBUTTON_13, 690, 335, 45, 100, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "电机控制", ID_HTEXT_0, 482, 112, 90, 35, 0, 0x0, 0 },
    { EDIT_CreateIndirect, "X_input", ID_HEDIT_0, 225, 50, 115, 35, 0, 0x64, 0 },
    { BUTTON_CreateIndirect, "SpeedM", ID_HBUTTON_14, 640, 170, 45, 30, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "SpeedH", ID_HBUTTON_15, 590, 170, 45, 30, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "BAK", ID_HBUTTON_16, 690, 225, 45, 45, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "SpeedL", ID_HBUTTON_17, 690, 170, 45, 30, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "绝对坐标", ID_HTEXT_1, 12, 13, 135, 33, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "X: 000.0mm", ID_HTEXT_2, 45, 52, 155, 35, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Y: 000.0mm", ID_HTEXT_3, 45, 90, 155, 37, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Z: 000.0mm", ID_HTEXT_4, 45, 130, 155, 35, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "XX", ID_HTEXT_5, 45, 246, 155, 35, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "YY", ID_HTEXT_6, 45, 296, 155, 35, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "ZZ", ID_HTEXT_7, 45, 341, 155, 35, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "相对坐标", ID_HTEXT_8, 10, 184, 135, 41, 0, 0x0, 0 },
    { EDIT_CreateIndirect, "Edit", ID_HEDIT_1, 225, 90, 115, 35, 0, 0x64, 0 },
    { EDIT_CreateIndirect, "Edit", ID_HEDIT_2, 225, 130, 120, 35, 0, 0x64, 0 },
    { TEXT_CreateIndirect, "步进电机控制", ID_HTEXT_9, 449, 176, 130, 25, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "归零", ID_HBUTTON_18, 250, 225, 85, 30, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "置零", ID_HBUTTON_19, 250, 345, 85, 30, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "机械归零", ID_HTEXT_10, 229, 190, 104, 20, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "归零", ID_HTEXT_11, 231, 313, 80, 20, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Xlim", ID_HTEXT_12, 500, 55, 75, 40, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Ylim", ID_HTEXT_13, 575, 55, 75, 40, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "ZLim", ID_HTEXT_14, 650, 55, 75, 40, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "C:00000", ID_HTEXT_15, 60, 390, 135, 35, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "Waring", ID_HTEXT_16, 211, 16, 175, 33, 0, 0x0, 0 },
    { TEXT_CreateIndirect, "F:0000", ID_HTEXT_17, 230, 390, 135, 35, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "m_start", ID_HBUTTON_20, 590, 112, 55, 30, 0, 0x0, 0 },
    { BUTTON_CreateIndirect, "m_stop", ID_HBUTTON_21, 660, 112, 55, 30, 0, 0x0, 0 },
	{ BUTTON_CreateIndirect, "置零", ID_HBUTTON_22, 250, 271, 85, 30, 0, 0x0, 0 },
};

uint8_t Pressed = 0;
uint8_t edit_index = 0;
extern uint8_t limit_en[3];
uint8_t ToZero = 0;
extern uint8_t handleWin_flag;
/*********************************************************************
*
*       _cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg)
{
    WM_HWIN hItem;
    int     NCode;
    int     Id;

    // USER START (Optionally insert additional variables)
    Pressed = 0;
    char x_edit_buf[10] = {0}; //X轴字符串接收
    char y_edit_buf[10] = {0};
    char z_edit_buf[10] = {0};
    float axis_val = 0;
    // USER END

    switch (pMsg->MsgId)
    {
        case WM_INIT_DIALOG:
            //
            // Initialization of 'Framewin'
            //
            hItem = pMsg->hWin;
            FRAMEWIN_SetSkinClassic(hItem);
            //FRAMEWIN_SetActive(hItem, 1);
            FRAMEWIN_SetTitleHeight(hItem, 32);
            FRAMEWIN_SetFont(hItem, &GUI_Fontfont20B);
            FRAMEWIN_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
            FRAMEWIN_SetText(hItem, "手动");
            FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
            FRAMEWIN_SetClientColor(hItem, GUI_MAKE_COLOR(0x00E7E7E7));

            //
            // Initialization of 设置键盘的相关功能
            //
            for(int i = ID_HBUTTON_0; i <= ID_HBUTTON_13; i ++)
            {
                hItem = WM_GetDialogItem(pMsg->hWin, i);
                BUTTON_SetFocussable(hItem, 0);  //按键失去聚焦

                if(i == ID_HBUTTON_11)
                    BUTTON_SetFont(hItem, GUI_FONT_20_1);
            }

            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_16);
            BUTTON_SetFocussable(hItem, 0); //退格失去聚焦
            //
            // Initialization of 'danji'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_0);
            TEXT_SetFont(hItem, &GUI_Fontfont20B);
            TEXT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER);
            //
            // Initialization of 'X_input'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_0);
            EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            EDIT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'SpeedM'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_14);
            BUTTON_SetText(hItem, "Middle");
            //
            // Initialization of 'SpeedH'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_15);
            BUTTON_SetText(hItem, "Fast");
            //
            // Initialization of 'SpeedL'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_17);
            BUTTON_SetText(hItem, "Slow");
            //
            // Initialization of 'jixie'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_1);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
            TEXT_SetFont(hItem, &GUI_Fontfont32B);
            //
            // Initialization of 'X: 000.00'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_2);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'Y: 000.00'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_3);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            //
            // Initialization of 'Z: 000.00'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_4);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            //
            // Initialization of 'XX'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_5);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "X: 000.0mm");
            //
            // Initialization of 'YY'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_6);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "Y: 000.0mm");
            //
            // Initialization of 'ZZ'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_7);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "Z: 000.0mm");
            //
            // Initialization of 'xiangdui'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_8);
            TEXT_SetFont(hItem, &GUI_Fontfont32B);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00000000));
            //
            // Initialization of 'Edit'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_1);
            EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            EDIT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'Edit'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_2);
            EDIT_SetFont(hItem, GUI_FONT_32B_1);
            EDIT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            //
            // Initialization of 'sepper'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_9);
            TEXT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER);
            TEXT_SetFont(hItem, &GUI_Fontfont20B);
            //
            // Initialization of 'label1'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_10);
            TEXT_SetFont(hItem, &GUI_Fontfont20B);
            //
            // Initialization of 'label2'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_11);
            TEXT_SetFont(hItem, &GUI_Fontfont20B);
            //
            // Initialization of 'Xlim'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_12);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'Ylim'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_13);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'ZLim'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_14);
            TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            //
            // Initialization of 'C:00000'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_15);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_BOTTOM);
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            // USER START (Optionally insert additional code for further widget initialization)
            //
            // Initialization of 'Dropdown'
            //
            // Initialization of 'm_fast'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_20);
            BUTTON_SetText(hItem, "Start");
            //
            // Initialization of 'm_mid'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_21);
            BUTTON_SetText(hItem, "Stop");

            //
            // Initialization of 'Waring'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);
            TEXT_SetFont(hItem, GUI_FONT_32_1);
            TEXT_SetText(hItem, "");
            //
            // Initialization of 'F:0000'
            //
            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_17);
            TEXT_SetTextAlign(hItem, GUI_TA_LEFT | GUI_TA_VCENTER);;
            TEXT_SetFont(hItem, GUI_FONT_32B_1);
            TEXT_SetText(hItem, "F:1.5cm/s");
			
			 hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_19);
			 BUTTON_SetFont(hItem, &GUI_Font20);
			 //TEXT_SetText(hItem,"123");
			 hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_22);
			 BUTTON_SetFont(hItem, &GUI_Font20);
			 hItem = WM_GetDialogItem(pMsg->hWin, ID_HBUTTON_18);
			 BUTTON_SetFont(hItem, &GUI_Font20);
            // USER END
            break;

        case WM_DELETE:
            handleWin_flag = 0;
            interpolation_para.endpoint_pulse = 0;
            z_axis_pul = 0;
            stepper_speed = 150;
            motor_speed_con(0);
            break;

        case WM_NOTIFY_PARENT:
            Id    = WM_GetId(pMsg->hWinSrc);
            NCode = pMsg->Data.v;


            if((Id >= ID_HBUTTON_0 && Id <= ID_HBUTTON_11) || Id == ID_HBUTTON_16)
            {
                switch(NCode)
                {
                    case WM_NOTIFICATION_CLICKED:
                        Pressed = 1;

                    case WM_NOTIFICATION_RELEASED:
                    {
                        int Key;

                        if(Id <= ID_HBUTTON_11)
                        {
                            char acBuffer[20];
                            BUTTON_GetText(pMsg->hWinSrc, acBuffer, sizeof(acBuffer)); /* Get the text of the button */
                            Key = acBuffer[0];
                        }
                        else
                        {
                            Key = GUI_KEY_BACKSPACE;
                        }

                        GUI_SendKeyMsg(Key, Pressed); /*Send a key message to the focussed window */
                    }
                    break;

                    default:
                        WM_DefaultProc(pMsg);
                }
            }

            switch(Id)
            {
                case ID_HBUTTON_12:
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:

                            // USER START (Optionally insert code for reacting on notification message)
                            switch(edit_index)
                            {
                                case 0:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_0);
                                    EDIT_SetText(hItem, "");
                                    break;

                                case 1:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_1);
                                    EDIT_SetText(hItem, "");
                                    break;

                                case 2:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_2);
                                    EDIT_SetText(hItem, "");
                                    break;
                            }

                            if(interpolation_para.motionstatus || z_axis_outStatus)
                            {
                                interpolation_para.endpoint_pulse = 0;
                                z_axis_pul = 0;
                            }

                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                    }

                    break;

                case ID_HBUTTON_13:
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:

                            // USER START (Optionally insert code for reacting on notification message)
                            switch(edit_index)
                            {
                                case 0:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_0);
                                    EDIT_GetText(hItem, x_edit_buf, 7);

                                    if(!stringTofloat(x_edit_buf, 7, &axis_val))
                                    {
                                        if(!limited_flag[0])
                                        {
                                            if(Liner_interpolationEx((int)(axis_val * 10), 0, stepper_speed))
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_YELLOW);
												TEXT_SetText(hItem, "data invalid");												
											}
											else
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_TRANSPARENT);
												TEXT_SetText(hItem, "");
											}
												
                                        }
                                        else
                                        {
                                            if(axis_val > 0)
                                            {
                                                limit_en[0] = 0;
												limit_en[1] = 0;
                                                Liner_interpolationEx((int)(axis_val * 10), 0, stepper_speed);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
                                        TEXT_SetBkColor(hItem, GUI_RED);
                                        TEXT_SetText(hItem, "data is invalid");
                                    }

                                    break;

                                case 1:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_1);
                                    EDIT_GetText(hItem, y_edit_buf, 7);

                                    if(!stringTofloat(y_edit_buf, 7, &axis_val))
                                    {
                                        if(!limited_flag[1])
                                        {
                                            if(Liner_interpolationEx(0, (int)(axis_val * 10), stepper_speed))
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_YELLOW);
												TEXT_SetText(hItem, "data invalid");												
											}
											else
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_TRANSPARENT);
												TEXT_SetText(hItem, "");
											}
                                        }
                                        else
                                        {
                                            if(axis_val > 0)
                                            {
                                                limit_en[0] = 0;
												limit_en[1] = 0;
                                                Liner_interpolationEx(0, (int)(axis_val * 10), stepper_speed);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
                                        TEXT_SetBkColor(hItem, GUI_RED);
                                        TEXT_SetText(hItem, "data is invalid");
                                    }

                                    break;

                                case 2:
                                    hItem = WM_GetDialogItem(pMsg->hWin, ID_HEDIT_2);
                                    EDIT_GetText(hItem, z_edit_buf, 7);

                                    if(!stringTofloat(z_edit_buf, 7, &axis_val))
                                    {
                                        if(!limited_flag[2])
                                        {
                                            if(Z_axisEx((int)(axis_val * 10), stepper_speed))
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_YELLOW);
												TEXT_SetText(hItem, "data invalid");												
											}
											else
											{
												hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
												TEXT_SetBkColor(hItem, GUI_TRANSPARENT);
												TEXT_SetText(hItem, "");
											}
                                        }
                                        else
                                        {
                                            if(axis_val < 0)
                                            {
                                                limit_en[2] = 0;
                                                Z_axisEx((int)axis_val * 10, stepper_speed);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_16);
                                        TEXT_SetBkColor(hItem, GUI_RED);
                                        TEXT_SetText(hItem, "data is invalid");
                                    }

                                    break;
                            }

                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                    }

                    break;

                case ID_HEDIT_0: // Notifications sent by 'X_input'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            edit_index = 0;
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;

                        case WM_NOTIFICATION_VALUE_CHANGED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_14: // Notifications sent by 'SpeedM'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            stepper_speed = 350;
                            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_17);
                            TEXT_SetText(hItem, "F:3.5cm/s");
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_15: // Notifications sent by 'SpeedH'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            stepper_speed = 150;
                            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_17);
                            TEXT_SetText(hItem, "F:6.5cm/s");
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_17: // Notifications sent by 'SpeedL'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            stepper_speed = 650;
                            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_17);
                            TEXT_SetText(hItem, "F:1.5cm/s");
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HEDIT_1: // Notifications sent by 'Edit'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            edit_index = 1;
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;

                        case WM_NOTIFICATION_VALUE_CHANGED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HEDIT_2: // Notifications sent by 'Edit'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            edit_index = 2;
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;

                        case WM_NOTIFICATION_VALUE_CHANGED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_18: // Notifications sent by 'J2Z'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
							if(ToZero == 0)
							{
								ToZero = 1;
							}
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_19: // Notifications sent by 'X2Z'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            MC_Execute_param.X_work_current = 0;
							MC_Execute_param.Y_work_current = 0;
							MC_Execute_param.Z_work_current = 0;
							MC_Execute_param.X_offset =MC_Execute_param.X_current - MC_Execute_param.X_work_current;
							MC_Execute_param.Y_offset =MC_Execute_param.Y_current - MC_Execute_param.Y_work_current;
							MC_Execute_param.Z_offset =MC_Execute_param.Z_current - MC_Execute_param.Z_work_current;
							// USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                case ID_HBUTTON_20: // Notifications sent by 'm_start'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            motor_speed_con(3);
                            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_15);
                            TEXT_SetText(hItem, "C:12000");
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;

                // USER START (Optionally insert additional code for further Ids)

                case ID_HBUTTON_21: // Notifications sent by 'm_stop'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            motor_speed_con(0);
                            hItem = WM_GetDialogItem(pMsg->hWin, ID_HTEXT_15);
                            TEXT_SetText(hItem, "C:00000");
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;
					
                case ID_HBUTTON_22: // Notifications sent by 'SZ'
                    switch(NCode)
                    {
                        case WM_NOTIFICATION_CLICKED:
                            // USER START (Optionally insert code for reacting on notification message)
                            MC_Execute_param.X_current = 0;
							MC_Execute_param.Y_current = 0;
							MC_Execute_param.Z_current = 0;
							MC_Execute_param.X_work_current = 0;
							MC_Execute_param.Y_work_current = 0;
							MC_Execute_param.Z_work_current = 0;
							MC_Execute_param.X_count = 0;
							MC_Execute_param.Y_count = 0;
							MC_Execute_param.Z_count = 0;
                            // USER END
                            break;

                        case WM_NOTIFICATION_RELEASED:
                            // USER START (Optionally insert code for reacting on notification message)
                            // USER END
                            break;
                            // USER START (Optionally insert additional code for further notification handling)
                            // USER END
                    }

                    break;
                    // USER END
            }

            break;

        // USER START (Optionally insert additional message handling)
        // USER END
        default:
            WM_DefaultProc(pMsg);
            break;
    }
}

extern uint8_t limited_flag[3];
WM_HWIN CreateHandlewin(void)
{
    WM_HWIN hWin;
    WM_HWIN hItem;
	char text2_buff[20];
	char text3_buff[20];
	char text4_buff[20];
	
    hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, HDTWIN, 0, 0);

    while(handleWin_flag)
    {
        if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_4))
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_12);
            TEXT_SetBkColor(hItem, GUI_RED);
        }
        else
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_12);
            TEXT_SetBkColor(hItem, GUI_GREEN);
        }

        if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_12))
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_13);
            TEXT_SetBkColor(hItem, GUI_RED);
        }
        else
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_13);
            TEXT_SetBkColor(hItem, GUI_GREEN);
        }

        if(!HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1))
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_14);
            TEXT_SetBkColor(hItem, GUI_RED);
        }
        else
        {
            hItem = WM_GetDialogItem(hWin, ID_HTEXT_14);
            TEXT_SetBkColor(hItem, GUI_GREEN);
        }
		
		//XIANSHSI
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_2);
		sprintf(text2_buff,"X: %.1fmm",((float)MC_Execute_param.X_current/10));
		TEXT_SetText(hItem,text2_buff);
		
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_4);
		sprintf(text4_buff,"Z: %0.1fmm",(float)MC_Execute_param.Z_current/10);
		TEXT_SetText(hItem,text4_buff);
		
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_3);
		sprintf(text3_buff,"Y: %.1fmm",((float)MC_Execute_param.Y_current/10));
		TEXT_SetText(hItem,text3_buff);
		//显示工作坐标
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_5);
		sprintf(text2_buff,"X: %.1fmm",((float)MC_Execute_param.X_work_current/10));
		TEXT_SetText(hItem,text2_buff);
		
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_7);
		sprintf(text4_buff,"Z: %0.1fmm",(float)MC_Execute_param.Z_work_current/10);
		TEXT_SetText(hItem,text4_buff);
		
		hItem = WM_GetDialogItem(hWin, ID_HTEXT_6);
		sprintf(text3_buff,"Y: %.1fmm",((float)MC_Execute_param.Y_work_current/10));
		TEXT_SetText(hItem,text3_buff);
		
		if(ToZero == 1 && interpolation_para.motionstatus == 0)
		{
			Liner_interpolationEx((int)(-1000 * 10),0 , 650);
			ToZero =2;
		}
		if(ToZero == 2 && interpolation_para.motionstatus == 0)
		{
			limit_en[0] = 0;
			Liner_interpolationEx(0 ,(int)(-1000 * 10), 650);
			//if()
				ToZero =3;
		}
		if(ToZero == 3 && interpolation_para.motionstatus == 0)
		{
			Z_axisEx((int)(1000 * 10), 650);
			limit_en[0] = 1;
			ToZero =0;			
		}
        GUI_Delay(30);
    }

    return hWin;
}


